package com.dc.project_java.test.lazy;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.dc.base.ui.fragment.BaseVmVbFragment;
import com.dc.base.view.recyclerview.commonadapter.ItemClickListener;
import com.dc.project_java.databinding.FragmentLazyBinding;

public class LazyFragment extends BaseVmVbFragment<LazyViewModel, FragmentLazyBinding> implements ItemClickListener {

    private LazyAdapter mAdapter;
    private String category;

    public static LazyFragment newInstance(String category) {
        Bundle bundle = new Bundle();
        bundle.putString("category", category);
        LazyFragment fragment = new LazyFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected void initView(@NonNull View view) {
        mAdapter = new LazyAdapter(activity);
        mAdapter.setItemClickListener(this);
        mViewBinding.rvList.setLayoutManager(new LinearLayoutManager(activity));
        mViewBinding.rvList.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {
        category = getArguments() != null ? getArguments().getString("category") : null;
    }

    @Override
    protected void lazyLoad() {
        mViewModel.loadData(category);
    }

    @Override
    protected void createObserver() {
        mViewModel.getJueJinLiveData().observe(this, jueJinBean -> mAdapter.setDatas(jueJinBean.getData()));
    }

    @Override
    public void onItemClick(int position) {

    }
}
